local __FILE__ = debug.getinfo(1, 'S').source:sub(2)
--print(__FILE__)

function dirname(str)
    if str:match(".-/.-") then
        local name = string.gsub(str, "(.*/)(.+)", "%1")
        return name
    elseif str:match(".-\\.-") then
        local name = string.gsub(str, "(.*\\)(.+)", "%1")
        return name
    else
        return ''
    end
end

--print(dirname(__FILE__))

-- cur script fold path
package.path = package.path .. ";" .. dirname(__FILE__) .. "?.lua"


--print(package.cpath)


require("cfg")

local function f1()
    local m = require("mod")
    m.hello()
    m.hello()
    m.hello()
end

local function main()
    f1()
end

local function log(...)
    print(string.format(...))
end

function __traceBack__(msg)
    local dbgInfo = debug.traceback()

    log("----------------------------------------")
    log("LUA ERROR: " .. tostring(msg) .. "\n")
    log(dbgInfo)
    log("----------------------------------------")

    local errstr = "LUA ERROR: " .. tostring(msg) .. "\n"
    errstr = errstr .. dbgInfo .. "\n"
    return msg
end

local status, msg = xpcall(main, __traceBack__)
if not status then
    error(msg)
end